package com.example.restaurantclient.Activity.Shop;

import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.restaurantclient.Adapter.ShopRecordAdapter;
import com.example.restaurantclient.ConfigUtil.ConfigUtil;
import com.example.restaurantclient.Entities.Order;
import com.example.restaurantclient.R;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;


public class ShopRecordActivity extends AppCompatActivity {

    private List<Order> orders = new ArrayList<>();
    private ListView lvRecord;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop_record);
//        sendPersonDateInfo(ConfigUtil.SERVER_ADDR);
//        initDate();
        lvRecord = findViewById(R.id.lv_record);
//        ShopRecordAdapter shopRecordAdapter = new ShopRecordAdapter(this,orders,R.layout.activity_shop_record_item);
//        lvRecord.setAdapter(shopRecordAdapter);
//        shopRecordAdapter.notifyDataSetChanged();
    }

//    public void initDate(){
//        if(Variable.loginIdentity == 1){
//            Thread t2=new Thread(){
//                @Override
//                public void run() {
//                    super.run();
//                    try {
//                        URL url = new URL(ConfigUtil.SERVER_ADDR+"ShopRecordServlet?teacherID="+ Variable.teacher.getId());
//                        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//                        //设置Http的请求方式：get、post、put、delete...,默认是get请求
//                        connection.setRequestMethod("POST");
//                        InputStream in = connection.getInputStream();
//                        byte[] buffer = new byte[2048];
//                        int len = in.read(buffer);
//                        String content = new String(buffer,0,len);
//                        Log.e("111",content);
//                        JSONArray jsonArray = new JSONArray(content);
//                        Log.e("111",jsonArray.toString());
//                        for (int i = 0; i < jsonArray.length(); i++){
//                            JSONObject jsonObject = jsonArray.getJSONObject(i);
//                            Order o = new Order();
//                            o.setOrder_id(jsonObject.getInt("order_id"));
//                            o.setTeacher_id(jsonObject.getInt("teacher_id"));
//                            o.setOrder_name(jsonObject.getString("order_name"));
//                            o.setOrder_tel(jsonObject.getString("order_tel"));
//                            o.setOrder_address(jsonObject.getString("order_address"));
//                            o.setOrder_remark(jsonObject.getString("order_remark"));
//                            o.setGoods_id(jsonObject.getInt("goods_id"));
//                            o.setGoods_name(jsonObject.getString("goods_name"));
//                            o.setGoods_integral(jsonObject.getInt("goods_integral"));
//                            o.setGoods_picture(jsonObject.getString("goods_picture"));
//                            orders.add(o);
//                        }
//                        System.out.println(orders.toString());
//                        Log.e("教师订单：",orders.toString());
//                        in.close();
//                    } catch (MalformedURLException e) {
//                        e.printStackTrace();
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                    } catch (JSONException e) {
//                        e.printStackTrace();
//                    }
//                }
//            };
//            t2.start();
//            try {
//                t2.join();
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }else {
//            Thread t3=new Thread(){
//                @Override
//                public void run() {
//                    super.run();
//                    try {
//                        URL url = new URL(ConfigUtil.SERVER_ADDR+"ShopRecordParentServlet");
//                        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//                        //设置Http的请求方式：get、post、put、delete...,默认是get请求
//                        connection.setRequestMethod("POST");
//                        InputStream in = connection.getInputStream();
//                        byte[] buffer = new byte[2048];
//                        int len = in.read(buffer);
//                        String content = new String(buffer,0,len);
//                        Log.e("111",content);
//                        JSONArray jsonArray = new JSONArray(content);
//                        Log.e("111",jsonArray.toString());
//                        for (int i = 0; i < jsonArray.length(); i++){
//                            JSONObject jsonObject = jsonArray.getJSONObject(i);
//                            Order o = new Order();
//                            o.setOrder_id(jsonObject.getInt("order_id"));
//                            o.setParent_id(jsonObject.getInt("parent_id"));
//                            o.setOrder_name(jsonObject.getString("order_name"));
//                            o.setOrder_tel(jsonObject.getString("order_tel"));
//                            o.setOrder_address(jsonObject.getString("order_address"));
//                            o.setOrder_remark(jsonObject.getString("order_remark"));
//                            o.setGoods_id(jsonObject.getInt("goods_id"));
//                            o.setGoods_name(jsonObject.getString("goods_name"));
//                            o.setGoods_integral(jsonObject.getInt("goods_integral"));
//                            o.setGoods_picture(jsonObject.getString("goods_picture"));
//                            orders.add(o);
//                        }
//                        System.out.println(orders.toString());
//                        Log.e("家长订单：",orders.toString());
//                        in.close();
//                    } catch (MalformedURLException e) {
//                        e.printStackTrace();
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                    } catch (JSONException e) {
//                        e.printStackTrace();
//                    }
//                }
//            };
//            t3.start();
//            try {
//                t3.join();
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }
//    }
//    public void sendPersonDateInfo(final String str){
//        Thread t1=new Thread(){
//            @Override
//            public void run() {
//                super.run();
//                try {
//                    URL url=null;
//                    if(Variable.loginIdentity==1){//教师
//                        url=new URL(str+"ReceiveTeacherIdShopRecordServlet"+"?teacherId="+Variable.teacher.getId());
//                    }else if(Variable.loginIdentity==2) {//家长
//                        url = new URL(str+"ReceiveParentIdShopRecordServlet" +"?parentId="+Variable.parent.getId());
//                    }
//                    url.openStream();
//                } catch (MalformedURLException e) {
//                    e.printStackTrace();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        };
//        t1.start();
//        try {
//            t1.join();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//    }

    @Override
    protected void onPause() {
        super.onPause();
        finish();
    }
}
